<style lang="less">
</style>

<template>
<div>
 <Card>  
        <p slot="title">
            <Icon type="navicon-round"></Icon>
            日志列表
        </p>
        
        <row>
            <i-col span="6">
    <Button-group>
        <Button @click="dellog">清理一周前日志</Button>
    </Button-group></i-col>
            <i-col span="4">
            </i-col>
            
            <i-col span="14">
            </i-col>
        </row>
    <div style="margin-top:10px"></div>
    <i-table :columns="cols" :data="data" stripe @on-sort-change="setorder"></i-table>
    
    <div style="margin-top:10px; text-align:center">
    <Page :total="pageinfo.total" :page-size="pageinfo.pagesize" show-sizer @on-change="pagechange" @on-page-size-change="pagesizechange"></Page></div>
    </Card>
    </div>
</template>

<script>
import api from '../../libs/api';
export default {
    name: 'log_index',
    data () {
        return {
            cols:[
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: 'ID',
                        key: 'ID',
                        width:60
                    },
                    {
                        title: 'mid',
                        key: 'mid',
                        width:60
                    },
                    {
                        title: '日志内容',
                        key: 'title',
                        align:'left'
                    },
                    {
                        title: '添加时间',
                        key: 'addtime',
                        align:'center',
                        width:160
                    },
                    {
                        title: 'IP',
                        key: 'ip',
                        align:'center',
                        width:120
                    }],
            
            data:[],
            pageinfo:{page:1,pagesize:20,total:0,order:"ID",esc:"desc"},            
            categorys:[],
        };
    },
    methods:{
        dellog(){
            var vm=this;
            api.post("/log/del").then(function(res){
                if(res.data.code==200){
                    vm.$Message.success(res.data.msg);
                }
                else{
                    vm.$Message.error(res.data.msg);
                }
            })
        },
        pagesizechange(pagesize){
            this.pageinfo.pagesize=pagesize;
            this.init();
        },
        pagechange(page){
            this.pageinfo.page=page;
            this.init();
        },
        setorder(column){
            if(column.order=="normal"){
            this.pageinfo.order="ID";
            this.pageinfo.esc="desc";
            }
            else{
            this.pageinfo.order=column.key;
            this.pageinfo.esc=column.order;
            }
            this.init();
        },
        getlist(){
            var vm=this;
            api.post("/log/getlist?t="+new Date().getSeconds(),this.pageinfo).then(function(res){
                vm.data=res.data.msg.Items;
                vm.pageinfo.total=res.data.msg.TotalItems;
            })
        },
        init(){
            this.getlist();
        }
    },
    created(){
        this.init();
    },
    watch: {
        '$route' () {
            this.init();
        }
    }
};
</script>
